<template>
<!-- 
  对于每个路由需要定义一个meta.title中文标识
  对于不需要跳转的路由可以定义一个redirect:'noredirect'
 -->
  <el-breadcrumb class="app-breadcrumb" separator-class="el-icon-arrow-right">
    <span style="float:left;">当前位置：</span>
    <transition-group name="breadcrumb">
      <el-breadcrumb-item v-for="(item,index)  in levelList" :key="item.path" v-if='item.meta.title'>
        <span v-if='item.redirect==="noredirect"||index==levelList.length-1' class="no-redirect">{{item.meta.title}}</span>
        <router-link v-else :to="item.path">{{item.meta.title}}</router-link>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>

<script>
  export default {
    name: 'JtBreadcrumb',
    created() {
      this.getBreadcrumb();
    },
    data() {
      return {
        levelList: null
      }
    },
    watch: {
      $route() {
        this.getBreadcrumb();
      }
    },
    methods: {
      getBreadcrumb() {
        let matched = this.$route.matched.filter(item => item.name);
        const first = matched[0]
        // if (first && first.name !== 'dashboard') {
        //   matched = [{
        //     path: '/dashboard',
        //     meta: {
        //       title: '概览'
        //     }
        //   }].concat(matched);
        // }
        this.levelList = matched;
      }
    }
  }

</script>

<style scoped>
  .app-breadcrumb.el-breadcrumb {
    color: #495060;
    display: inline-block;
    font-size: 13px;
    line-height: 26px;
  }
  .no-redirect {
    color: #7798d2;
    cursor: text;
  }
  .el-breadcrumb__inner a {
    color: #495060;
    font-weight: normal;
  }
</style>